<form id="addIdentValueForm" lay-filter="addIdentValueForm" class="layui-form model-form">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入名称" type="text" class="layui-input" maxlength="20"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="memo" placeholder="请输入描述" class="layui-textarea"
                      lay-verType="tips" ></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status" lay-skin="switch" lay-text="可用|不可用">
        </div>
    </div>
    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
        <button class="layui-btn" lay-filter="addIdentValueSubmit" lay-submit>保存</button>
    </div>
</form>

<script>
//获取权限方法
var userInfo = getAuthority();
var powerlist = JSON.parse(userInfo).permissions;
/*自定义函数判断权限*/
template.defaults.imports.hasPower = function(data){
    if(powerlist.includes(data)){
        return true;
    }
    return true;
};

layui.use(['layer', 'form', 'admin','tree'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var admin = layui.admin;
    var tree = layui.tree;
    var Authorization;//请求接口用

    var IdenValReq = window.IdenValReq;//接收所需参数
    if(userInfo){
            var access_token = localStorage.getExpire("access_token");
            var token_type = localStorage.getExpire("token_type");
            Authorization = token_type+" "+access_token;
    }

    form.render('checkbox')
    var obj={
        status:true
    }
    form.val('addIdentValueForm',obj);
    // 表单提交事件
    form.on('submit(addIdentValueSubmit)', function (data) {
        let req = {
            name:data.field.name,
            memo:data.field.memo,
            mid:IdenValReq.mid,
            vid:IdenValReq.vid,
            valueVersion:IdenValReq.valueVersion,
            parId:IdenValReq.parId,
            status:data.field.hasOwnProperty('status')?1:0
        }
        axios({
            method: 'POST',
            url:macroUrl.idenval.addVal,
            data:req,
            headers:{
                'Authorization':Authorization
            }
        })
            .then(function (response) {
                if(response.status == 200 &&response.data.message == "success"){
                    layer.closeAll('loading');
                    layer.msg("新增成功", {icon: 1});
                    window.addIdenValStatus=true;
                    admin.closeDialog("#addIdentValueForm");// 关闭页面层弹窗
                }else{
                    layer.closeAll('loading');
                    layer.msg(response.data.message, { icon: 2 });
                }
            })
            .catch(function (error) {
                console.log(error);
                if(error.response.status === 401 || error.response.status === 403 || error.response.status === 406){
                    // 进行重新登陆
                    localStorage.clear();
                    top.location.href=loginPageUrl;
                }
            });
        return false;
    });


});
</script>